/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.base.radar;

import com.hitechbangla.fctu.utility.GeneralUtil;
import fctu.simulator.HTB_MAIN;
import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;
import java.util.Random;

/**
 *
 * @author Asus
 */
public class ChaffEcm implements EcmDrawable, Serializable {
    
    private int radarPositionX;
    private int radarPositionY;
    private int aircraftPositionX;
    private int aircraftPositionY;
    private int radarRange;
    int d1 = 0;
    int d2 = 0;
    int d3 = 0;
    int d4 = 0;
    Random random;
    public ChaffEcm(int i, int i0, int x, int y, int  radarRange) {
	radarPositionX = i;
	radarPositionY = i0;
	aircraftPositionX = x;
	aircraftPositionY = y;
	this.radarRange = radarRange;
	Random random = new Random();
	d1 = GeneralUtil.getRandomIntegerInRange(1, 3, random) * (int) HTB_MAIN.one_px_equivalent_naut;
	d2 = GeneralUtil.getRandomIntegerInRange(2, 5, random) * (int) HTB_MAIN.one_px_equivalent_naut;
	d3 = GeneralUtil.getRandomIntegerInRange(3, 6, random) * (int) HTB_MAIN.one_px_equivalent_naut;
	d4 = GeneralUtil.getRandomIntegerInRange(4, 7, random) * (int) HTB_MAIN.one_px_equivalent_naut;
    }

    
    @Override
    public void draw(Graphics g, EpmType epmType) {
	//throw new UnsupportedOperationException("Not supported yet.");
	Random random = new Random();
	Color c = g.getColor();
	g.setColor(Color.black);
	g.setColor(Color.ORANGE);
	
	if (epmType == EpmType.PRFD || epmType == EpmType.PLD) {
	    d1 = 0;
	    d2 = 0;
	    d3 = 0;
	    d4 = 0;
	}
//	else if(epmType == EpmType.NONE){
//	    d1 = GeneralUtil.getRandomIntegerInRange(2, 5, random) * (int) HTB_MAIN.one_px_equivalent_naut;
//	    d2 = GeneralUtil.getRandomIntegerInRange(6, 11, random) * (int) HTB_MAIN.one_px_equivalent_naut;
//	}
	double distanceBetweenRadAndArcft = GeneralUtil.distance2D(aircraftPositionX, aircraftPositionY
					    , radarPositionX, radarPositionY);
	int distance = (int) distanceBetweenRadAndArcft;
	if(distance>= radarRange)
	{
	    GeneralUtil.log("Aircraft Out Of range!!");
	}else{
	    if( (int)GeneralUtil.distance2D(aircraftPositionX + d2 ,aircraftPositionY + d2,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX+d2, aircraftPositionY, 6, 6);
		g.fillRect(aircraftPositionX, aircraftPositionY+d2, 6, 6);
	    }
	    if( (int)GeneralUtil.distance2D(aircraftPositionX + d3 ,aircraftPositionY + d3,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX+d3, aircraftPositionY, 6, 6);
		g.fillRect(aircraftPositionX+d1, aircraftPositionY-d1, 6, 6);
		g.fillRect(aircraftPositionX+d2, aircraftPositionY+d1, 6, 6);
	    }
	    if( (int)GeneralUtil.distance2D(aircraftPositionX - d2 ,aircraftPositionY - d2,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX-d2, aircraftPositionY, 6, 6);
		g.fillRect(aircraftPositionX, aircraftPositionY-d2, 6, 6);
	    }
	    if( (int)GeneralUtil.distance2D(aircraftPositionX - d3 ,aircraftPositionY - d3,
		    radarPositionX, radarPositionY) < radarRange )
	    {
		g.fillRect(aircraftPositionX-d3, aircraftPositionY, 6, 6);
		g.fillRect(aircraftPositionX-d1, aircraftPositionY-d2, 6, 6);
	    }
	}
	g.setColor(c);
    }
    
    
}
